// servuce 统一出口
import HYRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'
import LocalCache from '@/utlis/cache'

// axios 实例
const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: config => {
      // 携带 token 的拦截
      const token = LocalCache.getCache('token') ?? ''
      if (token && config.headers) {
        config.headers.Authorization = `Bearer ${token}`
      }

      return config
    },
    requestInterceptorCatch(error) {
      console.log('请求失败的拦截')
      return error
    },
    reponseInterceptor: res => {
      return res
    },
    reponseInterceptorCatch(error) {
      console.log('响应失败的拦截')
      return error
    }
  }
})

// export const hyRequest2 = new HYRequest({
//   baseURL: '地址2'
// })

export default hyRequest
